<?php 
/* =================================== */
// UNFORMAT TEXT 
/* =================================== */
function my_formatter($content) {
	$new_content = '';
	$pattern_full = '{(\[raw\].*?\[/raw\])}is';
	$pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
	$pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);

	foreach ($pieces as $piece) {
		if (preg_match($pattern_contents, $piece, $matches)) {
			$new_content .= $matches[1];
		} else {
			$new_content .= wptexturize(wpautop($piece));
		}
	}

	return $new_content;
}

remove_filter('the_content', 'wpautop');
remove_filter('the_content', 'wptexturize');
add_filter('the_content', 'my_formatter', 99);
add_filter('widget_text', 'my_formatter', 99);

//HEADINGS
function arc_h1( $atts, $content = null ) {
	extract(shortcode_atts(array(
		'color' => ''
	), $atts));
   return "<h1 style=\"color: {$color};\">" . do_shortcode($content) . '</h1>';
} add_shortcode('h1', 'arc_h1');

function arc_h2( $atts, $content = null ) {
	extract(shortcode_atts(array(
		'color' => ''
	), $atts));
   return "<h2 style=\"color: {$color};\">" . do_shortcode($content) . '</h2>';
} add_shortcode('h2', 'arc_h2');

function arc_h3( $atts, $content = null ) {
	extract(shortcode_atts(array(
		'color' => ''
	), $atts));
   return "<h3 style=\"color: {$color};\">" . do_shortcode($content) . '</h3>';
} add_shortcode('h3', 'arc_h3');

function arc_h4( $atts, $content = null ) {
	extract(shortcode_atts(array(
		'color' => ''
	), $atts));
   return "<h4 style=\"color: {$color};\">" . do_shortcode($content) . '</h4>';
} add_shortcode('h4', 'arc_h4');

function arc_h5( $atts, $content = null ) {
	extract(shortcode_atts(array(
		'color' => ''
	), $atts));
   return "<h5 style=\"color: {$color};\">" . do_shortcode($content) . '</h5>';
} add_shortcode('h5', 'arc_h5');

function arc_h6( $atts, $content = null ) {
	extract(shortcode_atts(array(
		'color' => ''
	), $atts));
   return "<h6 style=\"color: {$color};\">" . do_shortcode($content) . '</h6>';
} add_shortcode('h6', 'arc_h6');

function arc_link($atts, $content = null){
	extract(shortcode_atts(array(
		'url' => '#',
		'target'=> '_blank',
		'color' => '',
		'alt' => ''
	),$atts));
	if (substr($url, 0, 7) != "http://") $url = "http://".$url;
	$result = "<a href='{$url}' target='{$target}' alt='{$alt}' style='color: {$color};'>{$content}</a>";
	return $result;
} add_shortcode('link', 'arc_link');


//NOTIFICATION BOXES
function arc_notify_success( $atts, $content = null ) {
   return '<div class="notbox"><div class="notbox_success"><p>'. do_shortcode($content) .'</p></div></div>';
} add_shortcode('notify_success', 'arc_notify_success');

function arc_notify_error( $atts, $content = null ) {
   return '<div class="notbox"><div class="notbox_error"><p>'. do_shortcode($content) .'</p></div></div>';
} add_shortcode('notify_error', 'arc_notify_error');

function arc_notify_warning( $atts, $content = null ) {
   return '<div class="notbox"><div class="notbox_warning"><p>'. do_shortcode($content) .'</p></div></div>';
} add_shortcode('notify_warning', 'arc_notify_warning');

function arc_notify_info( $atts, $content = null ) {
   return '<div class="notbox"><div class="notbox_info"><p>'. do_shortcode($content) .'</p></div></div>';
} add_shortcode('notify_info', 'arc_notify_info');


//CAPITALIZE
function arc_capitalize( $atts, $content = null ){
	extract(shortcode_atts(array(
		'bgcolor' => 'transparent',
		'fontcolor' => '#C1B565',
	), $atts));
	
	$style = "background-color: {$bgcolor}; color: {$fontcolor}; float:left; line-height: 28px; padding: 10px 9px 12px 5px; ";
	
	if ($bgcolor === 'transparent') {
		$style .= "font-size: 64px;";
		return '<div class="drop">
			<p><span class="drop1" style="'.$style.'">'. do_shortcode(substr($content,1,1)) .'</span>'. do_shortcode(substr($content,2)) .'</p>
		</div>';
	}  else {
		$style .= "font-size: 50px;";
		return '<div class="drop">
			<p><span class="drop2" style="'.$style.'">'. do_shortcode(substr($content,1,1)) .'</span>'. do_shortcode(substr($content,2)) .'</p>
		</div>';
	}	
} add_shortcode('capitalize', 'arc_capitalize');

//DIVIDERS
function arc_horizontal_divider($atts, $content=null){
	return '<div class="typedivider"></div>';
} add_shortcode('hr','arc_horizontal_divider'); add_shortcode('sep','arc_horizontal_divider');

function arc_horizontal_divider_dot($atts, $content=null){
	extract(shortcode_atts(array(
		'width' => 'auto'
	),$atts));
	$result = "<div style=\"border-bottom: 1px dotted #CCC; margin: 8px 0;height: 2px;\" class=\"typedivider-dot\" ";
	if ($width != 'auto') $result .= "width=\"{$width}\" ";
	$result .= "></div>";
	return $result;
} add_shortcode('hr_dot','arc_horizontal_divider_dot'); add_shortcode('sep_dot','arc_horizontal_divider_dot');


//COLUMNS
function arc_diver($atts, $content = null){
	return '<div class="tabela">'.do_shortcode($content).'</div>';
} add_shortcode('div', 'arc_diver');

function arc_one_oneth($atts, $content = null){
	return '<div class="one_oneth"><div style="padding: 10px 10px 10px 0; line-height: 16px;">'. do_shortcode($content) .'</div></div>';
} add_shortcode('one_oneth','arc_one_oneth');

function arc_one_half($atts, $content = null){
	return '<div class="one_half"><div style="padding: 10px 10px 10px 0; line-height: 16px;">'. do_shortcode($content) .'</div></div>';
} add_shortcode('one_half','arc_one_half');

function arc_one_half_last($atts, $content = null){
	return '<div class="one_half last"><div style="padding: 10px 10px 10px 0; line-height: 16px;">'. do_shortcode($content) .'</div></div>';
} add_shortcode('one_half_last','arc_one_half_last');

function arc_one_third($atts, $content = null){
	return '<div class="one_third"><div style="padding: 10px 10px 10px 0; line-height: 16px;">'. do_shortcode($content) .'</div></div>';
} add_shortcode('one_third','arc_one_third');

function arc_one_third_last($atts, $content = null){
	return '<div class="one_third last"><div style="padding: 10px 10px 10px 0; line-height: 16px;">'. do_shortcode($content) .'</div></div>';
} add_shortcode('one_third_last','arc_one_third_last');

function arc_two_third($atts, $content = null){
	return '<div class="two_third"><div style="padding: 10px 10px 10px 0; line-height: 16px;">'. do_shortcode($content) .'</div></div>';
} add_shortcode('two_third','arc_two_third');

function arc_two_third_last($atts, $content = null){
	return '<div class="two_third last"><div style="padding: 10px 10px 10px 0; line-height: 16px;">'. do_shortcode($content) .'</div></div>';
} add_shortcode('two_third_last','arc_two_third_last');

function arc_one_fourth($atts, $content = null){
	return '<div class="one_fourth"><div style="padding: 10px 10px 10px 0; line-height: 16px;">'. do_shortcode($content) .'</div></div>';
} add_shortcode('one_fourth','arc_one_fourth');

function arc_one_fourth_last($atts, $content = null){
	return '<div class="one_fourth last"><div style="padding: 10px 10px 10px 0; line-height: 16px;">'. do_shortcode($content) .'</div></div>';
} add_shortcode('one_fourth_last','arc_one_fourth_last');

function arc_three_fourth($atts, $content = null){
	return '<div class="three_fourth"><div style="padding: 10px 10px 10px 0; line-height: 16px;">'. do_shortcode($content) .'</div></div>';
} add_shortcode('three_fourth','arc_three_fourth');

function arc_three_fourth_last($atts, $content = null){
	return '<div class="three_fourth last"><div style="padding: 10px 10px 10px 0; line-height: 16px;">'. do_shortcode($content) .'</div></div>';
} add_shortcode('three_fourth_last','arc_three_fourth_last');

//ACCORDION
function arc_accordion($atts, $content = null){
	extract(shortcode_atts(array(
		'title' => '',
		'width' => '400px'
	), $atts));
	$result = "<script type=\"text/javascript\">
		$(document).ready(function() {
			$(\"#accordion\").tabs(\"#accordion div.pane\", {tabs: \"h3\", effect: \"slide\", initialIndex: 0});
			$(\".pane\").css(\"width\", \"{$width}\" );
			$(\"#accordion br\").remove();
		});	
	</script>";
	$result .= "<div id=\"accordion\" style=\"width:{$width}\"><h4>{$title}</h4>";
	$result .= do_shortcode($content);
	$result .= "</div>";
	return $result;
} add_shortcode('accordion','arc_accordion');

function arc_accordion_panel($atts, $content=null){
	extract(shortcode_atts(array(
		'title' => ''
	), $atts));
	$result = "<h3>{$title}</h3><div class=\"pane\"><div class=\"pane_c\">";
	$result .= do_shortcode($content);
	$result .= "</div></div>";
	return $result;
} add_shortcode('accordion_panel','arc_accordion_panel');

//TABS
function arc_tabs($atts, $content = null){
	extract(shortcode_atts(array(
		'title' => '',
		'width' => '',
		'howmany' => ''
	), $atts));
	$paneWidth = $width - 36;
	$result = "<div id=\"tabs\"><h4>{$title}</h4><ul class=\"tabs\" id=\"tabslist\">"; 
	for ($i = 0; $i < (int)$howmany; $i++){
		$result .= "<li></li>";
	}
	$result .="</ul><div class=\"panes\">";
	$result .= do_shortcode($content);
	$result .= "</div></div>";
	$result .= "<script type=\"text/javascript\">
		$(document).ready(function() {
			$(\"#tabs\").css(\"width\", \"{$width}\" );
			$(\".panes div\").css(\"width\", \"{$paneWidth}\" );
			$(\"#tabs .panes br\").remove();
			$(\".tabs\").tabs(\".panes > div\", {effect: \"fade\"});
		});	
	</script>";
	return $result;
} add_shortcode('tabs','arc_tabs');

function arc_tabs_panel($atts, $content=null){
	extract(shortcode_atts(array(
		'title' => ''
	), $atts));
	$result = "<div><p>".do_shortcode($content)."</p></div><script type='text/javascript'>";
	$result .= "$('#tabslist li').each(function(){ if ($(this).html() == ''){ $(this).html('<a href=\"#\">{$title}</a>'); return false; } });";
	$result .= "</script>";
	return $result;
} add_shortcode('tabs_panel','arc_tabs_panel');


//BUTTONS
function arc_button($atts, $content = null){
	extract(shortcode_atts(array(
		'bg_color' => '',
		'bg_hover_color' => '',
		'font_color' => '',
		'font_hover_color' => '',
		'padding' => '',
		'pre_styled' => '',
		'href' => '#',
		'width' => ''
	),$atts));
	$result = "";
	if ($pre_styled != ''){
		switch($pre_styled){
			case ($pre_styled === 'green' || $pre_styled === 'orange' || $pre_styled === 'red' || $pre_styled === 'yellow'):
				$result .= "<a class=\"arc_button_{$pre_styled} round_corners\" href=\"{$href}\" ";
				$result .= "style=\"";
				if ($width != '') $result .= "width: {$width}; ";
				if ($padding != '') $result .= "padding: {$padding};";
				$result .= "\">";
				$result .= do_shortcode($content);
				$result .= "</a>";
				break;
			default: $result .= "<a class=\"arc_button round_corners\" href=\"{$href}\" ";
				$result .= "style=\"";
				if ($width != '') $result .= "width: {$width}; ";
				if ($padding != '') $result .= "padding: {$padding};";
				$result .= "\">";
				$result .= do_shortcode($content);
				$result .= "</a>";
				break;
		}
	} else {
		$randomID = uniqid();
		$result .= "<a id=\"{$randomID}\" class=\"arc_button round_corners\" href=\"{$href}\" style=\";";
		if ($bg_color != '') $result .= "background-color: {$bg_color}; ";
		if ($font_color != '') $result .= "color: {$font_color}; ";
		if ($padding != '') $result .= "padding: {$padding}; ";
		$result .= "\">";
		$result .= do_shortcode($content);
		$result .= "</a>";
		$result .= "<script type=\"text/javascript\">
			$(document).ready(function(){
				$('#{$randomID}').hover(function(){
					$(this).css({
						'background':'{$bg_hover_color}',
						'color': '{$font_hover_color}'	
					});
				}, function(){
					$(this).css({
						'background':'{$bg_color}',
						'color':'{$font_color}'
					});
				});
			});
		</script>";
	}
	$result .= "<script type=\"text/javascript\">
			$(document).ready(function(){
				$('a br').remove();
			});</script>";
	return $result;
}add_shortcode('button','arc_button');

// MEDIA
// Insert Image
function arc_image($atts,$content = null){
	extract(shortcode_atts(array(
		'url' => '',
		'alt' => '',
		'href' => '',
		'resize' => 'false',
		'width' => '',
		'height' => '',
		'top' => '',
		'left' => '',
		'bottom' => ''
	),$atts));
	if ($href != '' && $href != 'optional'){
		$result = "<a href=\"{$href}\" style=\"padding-top:{$top}; padding-left:{$left}; padding-bottom:{$bottom};\" >";
	}
	$result .= "<img src=\"{$url}\" alt=\"{$alt}\" ";
	if ($resize === 'true'){
		$result .= "width=\"{$width}\" height=\"{$height}\" ";
	}
	if ($href == '' || $href == 'optional'){
		$result .= "style=\"margin-top:{$top}; margin-left:{$left}; margin-bottom:{$bottom}\">";
	} else $result .= " />";
	if ($href != '' && $href != 'optional'){
		$result .= "</a>";
	}
	return $result;
} add_shortcode('image','arc_image');

// Insert youtube video
function arc_video($atts,$content = null){
	extract(shortcode_atts(array(
		'url' => '',
		'resize' => 'false',
		'width' => '640px',
		'height' => '390px'
	),$atts));
	$stripURL = explode('v=', $url);
	$stripURL = explode('&',$stripURL[1]);
	$url = 'http://www.youtube.com/v/'.$stripURL[0];
	if ($resize === "false" || $resize === ''){ 
		$width = '640px';
		$height = '390px';
	}
	//$result = "<iframe width=\"{$width}\" height=\"{$height}\" frameborder=\"0\" src=\"{$url}\" type=\"text/html\" class=\"youtube-player\" title=\"YouTube video player\"></iframe>";
	$result = "<object width='{$width}' height='{$height}'><param name='movie' value='{$url}?autoplay=1&version=3&amp;hl=pt_PT'></param><param name='wmode' value='transparent'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='{$url}?autoplay=1&version=3&amp;hl=pt_PT' type='application/x-shockwave-flash' width='{$width}' height='{$height}' allowscriptaccess='always' allowfullscreen='true' wmode='transparent'></embed></object>";
	return $result;
} add_shortcode('video','arc_video');


//UL's
function arc_ul($atts, $content = null){
	extract(shortcode_atts(array(
		'type' => 'check',
		'color' => 'blue'
	),$atts));
	$class = "url(\"";
	$class .= get_template_directory_uri();
	$class .= "/img/li";
	if ($type === 'arrow' || $type === 'dot' || $type === 'corner' || $type === 'star'){
		$class .= "_{$type}";
	} else $class .= "_check";
	if ($color === 'green' || $color === 'orange' || $color === 'red' || $color === 'yellow' ){
		$class .= "_{$color}";
	} else $class .= "_blue";
	if ($type === 'star') $class .= ".png\") no-repeat scroll 2px 4px transparent";
	else $class .= ".png\") no-repeat scroll 6px 4px transparent";
	$randomID = uniqid();
	$result = "<ul id=\"{$randomID}\">";
	$result .= do_shortcode($content);
	$result .= "</ul>";
	$result .= "<script type=\"text/javascript\">
		$(document).ready(function(){
			$(\"#{$randomID}\").find(\"li\").css({
				'background': '{$class}',
				'display': 'block',
				'height': '16px',
				'margin-left': '10px',
				'padding-left': '20px',
				'position': 'relative'				
			});
		});
	</script>";
	return $result;
} add_shortcode('ul','arc_ul');


//LI's
function arc_li($atts, $content = null){
	extract(shortcode_atts(array(
		'type' => 'check',
		'color' => 'blue'
	),$atts));
	$class = "url('";
	$class .= get_template_directory_uri();
	$class .= "/img/li";
	if ($type === 'arrow' || $type === 'dot' || $type === 'corner' || $type === 'star'){
		$class .= "_{$type}";
	} else $class .= "_check";
	if ($color === 'green' || $color === 'orange' || $color === 'red' || $color === 'yellow' ){
		$class .= "_{$color}";
	} else $class .= "_blue";
	if ($type === 'star') $class .= ".png') no-repeat scroll 2px 4px transparent !important; display: block; height: 16px; margin-left: 10px; padding-left: 20px; position: relative";
	else $class .= ".png') no-repeat scroll 6px 3px transparent !important; display: block; height: 16px; margin-left: 10px; padding-left: 20px; position: relative";
	$result = "<li style=\"background: {$class};\">";
	$result .= do_shortcode($content);
	$result .= "</li>";
	$result .= "<script type=\"text/javascript\">
		$('li').parent().find('br').remove();
	</script>";
	return $result;
} add_shortcode('li','arc_li');


//CONTAINER'S
function arc_container_fullsize($atts, $content = null){
	$result = "<div class=\"textbg\" style=\"background: url('".get_template_directory_uri()."/img/textbg1.png'); height: 100%; left: 30px; position: relative; top: 23px; width: 735px; padding: 20px;\"";
	$result .= do_shortcode($content);
	$result .= "</div>";
	return $result;
} add_shortcode('container_fullsize', 'arc_container_fullsize');

function arc_container_cornered($atts, $content=null){
	$result = "<div class=\"about\"><div class=\"aligntxt\">".do_shortcode($content)."</div></div>";
	return $result;
} add_shortcode('container_cornered','arc_container_cornered');

function arc_container_vertical($atts, $content=null){
	$result = "<div class=\"about_vertical\"><div class=\"aligntxt\">".do_shortcode($content)."</div></div>";
	return $result;
} add_shortcode('container_vertical','arc_container_vertical');

function arc_container_simple($atts, $content=null){
	$result = "<div class=\"about_simple\"><div class=\"aligntxt\">".do_shortcode($content)."</div></div>";
	return $result;
} add_shortcode('container_simple','arc_container_simple');
?>